/**
 * storage util
 */

  var storage = (function (){
      var data = {};

      if (window.is){
          data = $.extend(true, window.is, {
              page: window.is.CONST.pages ? window.is.CONST.pages[0] : null,

              editMode: null,
              dragging: false,
              showlist: false,
              play_music: false,
              disableCanvasSelectable: false,

              is_only_red: true,
              is_edit_video: false,
              is_edit_music: false,
              is_edit_u3d: false,
              is_edit_album: false,

              page_timelines: {},
              showTimeline: false,
              turning_antype: null,

              widgetAllVisible: true,
              toggleAllVisible: true,
              toggleAllLineVisible: true,

              selectedWidgetIds: [],
              selectedAnType: null,
              selectedWidgetId: null,
              selectedAnTypeId: null,
              selectedTimeline: null,
              selectedTimelineId: null,
              selectedWidgetTimelineId: null,

              open_permission_tip: false,
              widgetsCopy: null,

              max_time: 0,
              max_end_time: 0,

              i18n_base_path: window.i18n_base_path || "",
              preloadImg: window.preloadImg || "",
              lan: window.lan,

              stillAnimation: false, // h5动效播放标志

              switchType: "PlaneAR",
              shiftKey: '', //标记是否按下shift键
          });
      }

      var hasRepeatWidgetId = function (widgetId){
          var ids = data.selectedWidgetIds;
          var result = ids.filter(function (id){
              return widgetId === id;
          });
          return !!result.length;
      };

      return {
          data: data,
          addSelectedWidgetId: function (widgetId, isShift){
              var ids = data.selectedWidgetIds;
              if (!hasRepeatWidgetId(widgetId)){
                  ids.push(widgetId);
              } else {
                  if(isShift){
                     var index = ids.indexOf(widgetId);
                     ids.splice(index,1);
                  }
              }
          }
      }
  })();

  module.exports = storage;
